package com.infore.dataReceiving.core.filter.instructions;
import com.infore.dataReceiving.core.chain.Water2018InstructionsChain;
import com.infore.dataReceiving.core.enums.Water2018InstructionsTypeEnum;
import com.infore.dataReceiving.core.enums.ResultEnum;
import com.infore.dataReceiving.core.filter.Water2018InstructionsFilter;
import com.infore.dataReceiving.dto.WaterInstructionsDto;
import com.infore.dataReceiving.repository.IBackControlLogRepository;
import com.infore.dataReceiving.util.RedisUtil;
import io.netty.channel.ChannelHandlerContext;

/**
 * 返回执行结果
 * @author 69457
 *
 */
public class ResultFilter implements Water2018InstructionsFilter{
	
	@Override
	public void doFilter(ChannelHandlerContext ctx,WaterInstructionsDto dto, 
			Water2018InstructionsChain chain,RedisUtil redisUtil,IBackControlLogRepository repository, boolean interrupt) {
		if(Water2018InstructionsTypeEnum.water2018_9012.getCn().equals(dto.getCn())) {
			interrupt = true;
			try {
				System.out.println("正在更新返回执行结果！！！！！！！！！！！！！");
				String exeRtn = dto.getExeRtn();
				String result = "";
				if(ResultEnum.result_1.getCode().equals(exeRtn)) {
					result = ResultEnum.result_1.getMsg();
				}else if(ResultEnum.result_2.getCode().equals(exeRtn)) {
					result = ResultEnum.result_2.getMsg();
				}else if(ResultEnum.result_3.getCode().equals(exeRtn)) {
					result = ResultEnum.result_3.getMsg();
				}else if(ResultEnum.result_4.getCode().equals(exeRtn)) {
					result = ResultEnum.result_4.getMsg();
				}else if(ResultEnum.result_5.getCode().equals(exeRtn)) {
					result = ResultEnum.result_5.getMsg();
				}else if(ResultEnum.result_6.getCode().equals(exeRtn)) {
					result = ResultEnum.result_6.getMsg();
				}else if(ResultEnum.result_100.getCode().equals(exeRtn)) {
					result = ResultEnum.result_100.getMsg();
				}else {
					result = "未知错误！！";
				}
				String mn = dto.getMn();
				String qn = dto.getQn();
				repository.updateResultFlag(result,mn, qn);
			} catch (Exception e) {
				System.out.println("更新返回执行结果错误：");
			}
		}
		chain.doFilter(ctx,dto,chain,redisUtil,repository,interrupt);
	}
	
}
